package com.bw.controller;

import com.bw.bean.Login;
import com.bw.bean.Stu;
import com.bw.service.StuService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class MyController {
    @Resource
    private StuService service;


    @RequestMapping("login")
    public String login(){
        return "login";
    }
    @RequestMapping("logins")
    @ResponseBody
    public boolean logins(Login login){
        Login sel = service.sel(login);
        if(sel.getName().equals(login.getName()) && sel.getPawass().equals(login.getPawass())){
            return true;
        }else {
            return false;
        }


    }

    @RequestMapping("tolist")
    public String tolist(Model model){
        List<Stu> list = service.list();
        model.addAttribute("list",list);
        return "list";
    }
    @RequestMapping("toadd")
    public String toadd(){

        return "add";
    }
    @RequestMapping("add")
    public String add(Stu stu){
        service.insert(stu);
        return "redirect:tolist.do";
    }
}
